<template>
	<!-- 处罚和奖励一样，记得同步 -->
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px"
			class="queryForms">
			<el-form-item label="处罚人/部门" prop="awardPerson">
				<el-input v-model="queryParams.awardPerson" placeholder="请输入处罚人/部门" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="处罚方式" prop="rewardMethodKey">
				<el-select v-model="queryParams.rewardMethodKey" placeholder="请选择">
					<el-option v-for="dict in dict.type.quality_type_reward1" :key="dict.value" :label="dict.label"
						:value="dict.value"> </el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="处罚时间" prop="awardtime">
				<el-date-picker v-model="queryParams.awardtime" type="daterange" value-format="yyyy-MM-dd"
					range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker>
			</el-form-item>
			<el-form-item label="状态" prop="approvalStatus">
				<el-select v-model="queryParams.approvalStatus" placeholder="请选择">
					<el-option v-for="dict in dict.type.default_approve" :key="dict.value" :label="dict.label"
						:value="dict.value"> </el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
					v-hasPermi="['quality:qualityExam2:apply']">申请</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
					v-hasPermi="['quality:qualityExam2:remove']">删除</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="primary" icon="el-icon-circle-check" size="mini" @click="handleSubmits"
					v-hasPermi="['quality:qualityExam2:approve']">提交</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="primary" icon="el-icon-s-order" size="mini" @click="handleApprove"
					v-hasPermi="['quality:qualityExam2:approve2']">审批</el-button>
			</el-col>
			<!-- <span>生成表单</span> -->
			<CreateForm :ids="ids" formtype="t_measuring_equipment2" />
			<right-toolbar menuNames="qualityExam244" @changeTableData="changeTableData" :showSearch.sync="showSearch"
				@queryTable="getList" :columns.sync="columns" perm="quality:qualityExam2:index"></right-toolbar>
		</el-row>

		<div :class="sidebar.opened && eleTabTop <= 85 ? 'eleTab' : !sidebar.opened && eleTabTop <= 85 ? 'eleTabs' : ''"
			class="informationTab" ref="eleTab">
			<el-table ref="table" @row-click="row_click" v-loading="loading" :data="auxiliaryConsumablesList"
				@selection-change="handleSelectionChange" border height="100%">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="序号" align="center" type="index" width="55" />
				<el-table-column label="记录编号" prop="recordNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[0].visible" />
				<el-table-column label="编号" prop="number" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[1].visible" />
				<el-table-column label="申请人" prop="informantName" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[2].visible" />
				<el-table-column label="申请部门" prop="deptName" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[3].visible" />
				<el-table-column label="处罚人" prop="awardPerson" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[4].visible" />

				<el-table-column label="处罚部门" prop="awardDept" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[12].visible" />
				<el-table-column label="所属部门" prop="belongingDept" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[5].visible" />
				<el-table-column label="处罚方式" prop="rewardMethodKey" min-width="170" :show-overflow-tooltip="true"
					v-if="columns[6].visible">
					<template slot-scope="scope">
						<dict-tag :options="dict.type.quality_type_reward1" :value="scope.row.rewardMethodKey" />
					</template>
				</el-table-column>
				<el-table-column label="处罚时间" align="center" min-width="210" :show-overflow-tooltip="true"
					v-if="columns[7].visible">
					<template slot-scope="scope"> {{ scope.row.awardTimeStart }} 至 {{ scope.row.awardTimeEnd }}
					</template>
				</el-table-column>
				<el-table-column label="处罚金额" align="center" prop="rewardAmount" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[8].visible" />
				<el-table-column label="原因描述" prop="remark" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[9].visible" />
				<el-table-column label="文件号" prop="fileNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[10].visible" />
				<!-- <el-table-column label="审核状态" prop="approvalStatus" min-width="150" :show-overflow-tooltip="true" /> -->
				<el-table-column label="状态" prop="approvalStatus" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[11].visible">
					<template slot-scope="scope">
						<!-- <div @click="showApproveList(scope.row)">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.approvalStatus" />
						</div> -->
						<el-tag type="info" v-if="scope.row.approvalStatus === '0'" class="disableClick">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.approvalStatus" />
						</el-tag>
						<el-tag v-if="scope.row.approvalStatus === '1'" @click="showApproveList(scope.row)"
							class="clickable">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.approvalStatus" />
						</el-tag>
						<el-tag type="success" v-if="scope.row.approvalStatus === '2'"
							@click="showApproveList(scope.row)" class="clickable">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.approvalStatus" />
						</el-tag>
						<el-tag type="danger" v-if="scope.row.approvalStatus === '3'"
							@click="showApproveList(scope.row)" class="clickable">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.approvalStatus" />
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" class-name="small-padding fixed-width" fixed="right" width="180">
					<template slot-scope="scope">
						<el-button size="mini" type="text" icon="el-icon-circle-check" @click="handleSubmit(scope.row)"
							v-if="scope.row.approvalStatus == '0' || scope.row.approvalStatus == '3'"
							v-hasPermi="['quality:qualityExam2:approve']">提交</el-button>
						<!-- 审批中显示 -->
						<el-button size="mini" type="text" icon="el-icon-edit" @click="handleApprove(scope.row)"
							v-if="scope.row.approvalStatus == '1' && scope.row.userApprovalStatus == '0'"
							v-hasPermi="['quality:qualityExam2:approve2']">审批</el-button>
						<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
							v-hasPermi="['quality:qualityExam2:edit']"
							v-if="scope.row.approvalStatus == '0' || scope.row.approvalStatus == '3'">修改</el-button>
						<el-dropdown size="mini" @command="command => handleCommand(command, scope.row)"
							v-hasPermi="['quality:qualityExam2:remove', 'quality:qualityExam2:annex']">
							<el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
							<el-dropdown-menu slot="dropdown">
								<el-dropdown-item command="handleDelete" v-hasPermi="['quality:qualityExam2:remove']"
									v-if="scope.row.approvalStatus == '0' || scope.row.approvalStatus == '3'">删除</el-dropdown-item>
								<el-dropdown-item command="handleAnnex"
									v-hasPermi="['quality:qualityExam2:annex']">附件</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
						<!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['quality:qualityExam2:remove']">删除</el-button>
						<el-button size="mini" type="text" icon="el-icon-wallet" @click="handleAnnex(scope.row)" v-hasPermi="['quality:qualityExam2:annex']">附件</el-button> -->
					</template>
				</el-table-column>
			</el-table>
		</div>

		<pagination menuNames="Pagination47" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
			:limit.sync="queryParams.pageSize" @pagination="getList" />

		<!-- 添加或修改处罚对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body v-dialogDrag>
			<el-form ref="form" :model="form" :rules="rules" label-width="130px" class="add-form2">
				<el-form-item label="记录编号" prop="recordNumber">
					<el-input v-model="form.recordNumber" placeholder="请输入记录编号" disabled />
				</el-form-item>
				<el-form-item label="编号" prop="number">
					<el-input v-model="form.number" placeholder="请输入编号" maxlength="20" show-word-limit />
				</el-form-item>
				<el-form-item label="申请人" prop="informantName">
					<el-input v-model="form.informantName" placeholder="请输入申请人" maxlength="20" show-word-limit />
				</el-form-item>
				<el-form-item label="申请部门" prop="deptId">
					<el-cascader ref="deptref" v-model="form.deptId" :options="deptList"
						:props="{ expandTrigger: 'click', value: 'id', emitPath: false, checkStrictly: true }"
						@change="changeDept()"></el-cascader>
				</el-form-item>
				<el-form-item label="处罚人/处罚部门" prop="awardType">
					<!-- <el-input v-model="form.awardPerson" placeholder="请输入奖励人/部门" maxlength="20" show-word-limit  /> -->
					<el-select v-model="form.awardType">
						<el-option v-for="item in awardTypeList" :key="item.id" :label="item.name"
							:value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="处罚人" prop="awardPerson" v-if="form.awardType == '0'">
					<el-input v-model="form.awardPerson" placeholder="请输入奖励人" maxlength="20" show-word-limit />
				</el-form-item>
				<el-form-item label="处罚部门" prop="awardDept" v-if="form.awardType == '1'">
					<el-input v-model="form.awardDept" placeholder="请输入奖励部门" maxlength="20" show-word-limit />
				</el-form-item>
				<el-form-item label="所属部门" prop="belongingDeptId">
					<el-cascader ref="belongingDeptref" v-model="form.belongingDeptId" :options="deptList"
						:props="{ expandTrigger: 'click', value: 'id', emitPath: false, checkStrictly: true }"
						@change="changeBelongingDept()"></el-cascader>
				</el-form-item>
				<el-form-item label="处罚方式" prop="rewardMethodKey">
					<el-select v-model="form.rewardMethodKey" placeholder="请选择">
						<el-option v-for="dict in dict.type.quality_type_reward1" :key="dict.value" :label="dict.label"
							:value="dict.value"> </el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="处罚时间" prop="awardtime">
					<el-date-picker v-model="form.awardtime" type="daterange" value-format="yyyy-MM-dd"
						range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker>
				</el-form-item>
				<!-- awardTimeEnd，awardTimeStart -->
				<el-form-item label="处罚金额" prop="rewardAmount">
					<el-input-number v-model="form.rewardAmount" placeholder="请输入处罚金额" :min="0" :max="99999999"
						:precision="2" />
				</el-form-item>
				<el-form-item label="文件号" prop="fileNumber">
					<el-input v-model="form.fileNumber" placeholder="请输入文件号" maxlength="20" show-word-limit />
				</el-form-item>
				<el-form-item label="原因描述" prop="remark" style="width: 100%">
					<el-input v-model="form.remark" type="textarea" placeholder="请输入原因描述" maxlength="100"
						show-word-limit />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
		<!-- 审批弹框 -->
		<el-dialog title="审批" :visible.sync="openApprove" width="900px" append-to-body v-dialogDrag>
			<ApproveTemplete @cancelApprove="cancelApprove" :openApprove="openApprove"></ApproveTemplete>
		</el-dialog>
		<!-- 审批流程弹框 -->
		<el-dialog title="审批流程" :visible.sync="openRecords" width="900px" append-to-body v-dialogDrag>
			<RecordsTemplete :approveRecord="approveRecord"></RecordsTemplete>
		</el-dialog>
	</div>
</template>

<script>
import { listQuality, getQuality, delQuality, addQuality, updateQuality, getNumber, submitQuality, qualityApprove } from "@/api/quality/qualityExam"
import CreateForm from "@/views/components/CreateForm"
import { deptTreeSelect } from "@/api/system/user"
import ApproveTemplete from "@/views/components/ApproveTemplete"
import { approvalRecord } from "@/api/productTechnology/productTechnologyVersions"
import RecordsTemplete from "@/views/components/RecordsTemplete"
import { deepClone } from "@/utils/index"
import { mapGetters } from "vuex"
import { getcolumn } from "@/api/selectList"
import searchStateMixin from '@/layout/mixin/searchStateMixin.js' 
export default {
	name: "QualityExam2",
	mixins: [searchStateMixin], 
	components: { ApproveTemplete, CreateForm, RecordsTemplete },
	dicts: ["quality_type_reward1", "default_approve"],
	data() {
		return {
			awardTypeList: [
				{
					id: "0",
					name: "处罚人"
				},
				{
					id: "1",
					name: "处罚部门"
				}
			],
			eleTabTop: 0, //表格容器距浏览器顶部距离
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// 处罚表格数据
			auxiliaryConsumablesList: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				awardPerson: undefined,
				awardtime: undefined,
				awardTimeEnd: undefined,
				awardTimeStart: undefined,
				approvalStatus: undefined
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {
				number: [{ required: true, message: "请输入编号", trigger: "blur" }],
				informantName: [{ required: true, message: "请输入申请人", trigger: "blur" }],
				deptId: [{ required: true, message: "请选择申请部门", trigger: "change" }],
				awardPerson: [{ required: true, message: "请输入处罚人", trigger: "blur" }],
				awardDept: [{ required: true, message: "请输入处罚部门", trigger: "blur" }],
				belongingDeptId: [{ required: true, message: "请选择所属部门", trigger: "change" }],
				rewardAmount: [{ required: true, message: "请输入处罚金额", trigger: "blur" }],
				rewardMethodKey: [{ required: true, message: "请选择处罚方式", trigger: "change" }],
				awardtime: [{ required: true, message: "请选择处罚时间", trigger: "change" }],
				awardType: [{ required: true, message: "请选择处罚人/部门", trigger: "blur" }]
			},
			// 处罚类型列表
			auxiliaryTypes: [],
			// 用户列表
			deptList: [],
			// 审批数据
			openApprove: false,
			approveRow: undefined,
			openRecords: false,
			approveRecord: [],
			// 列信息
			columns: [
				{ key: 0, label: `记录编号`, visible: true },
				{ key: 1, label: `编号`, visible: true },
				{ key: 2, label: `申请人`, visible: true },
				{ key: 3, label: `申请部门`, visible: true },
				{ key: 4, label: `处罚人`, visible: true },
				{ key: 5, label: `所属部门`, visible: true },
				{ key: 6, label: `处罚方式`, visible: true },
				{ key: 7, label: `处罚时间`, visible: true },
				{ key: 8, label: `处罚金额`, visible: true },
				{ key: 9, label: `原因描述`, visible: true },
				{ key: 10, label: `文件号`, visible: true },
				{ key: 11, label: `计划状态`, visible: true },
				{ key: 12, label: `处罚部门`, visible: true }
			]
		}
	},
	computed: {
		...mapGetters(["sidebar"])
	},
	mounted() {
		// 滚动条的获取
		this.handleScrollx()
		window.addEventListener("scroll", this.handleScrollx, true)
	},
	activated() {
		// this.getSize()
		//获取表格容器距页面头部的距离
		this.handleScrollx()
	},
	destroyed() {
		window.removeEventListener("scroll", this.handleScrollx, true)
	},
	created() {
		// 如果是页面刷新，重置查询
		if (window.performance && performance.navigation.type === performance.navigation.TYPE_RELOAD) {
			// 清除URL中的查询参数（不刷新页面）
			this.resetForm("queryForm")
			window.history.replaceState({}, document.title, window.location.pathname)
		}
		// this.getSize()
	},
	watch: {
		"$route.query": {
			handler(newQuery, oldQuery) {
				if (newQuery.queryData) {
					if (Object.keys(newQuery.queryData).length === 0) {
						this.resetQuerys()
						// this.getSize()
					} else {
						this.queryParams = { ...this.queryParams, ...JSON.parse(newQuery.queryData) }
						// this.getSize()
					}
				} this.getSize()
			},
			immediate: true, // 立即执行一次
			deep: true // 深度监听
		}
	},
	methods: {
		getSize() {
			getcolumn({ pageName: "Pagination47" }).then(response => {
				this.queryParams.pageSize = response.data.length ? (response.data[0].limit ? response.data[0].limit : 10) : 10
				this.getList()
			})
		},
		// 单击表格行
		row_click(row, column, event) {
			if (column && column.label == "操作") {
				return
			} else {
				this.$refs.table.toggleRowSelection(row)
			}
		},
		changeTableData() {
			this.$nextTick(() => {
				this.$refs.table.doLayout()
			})
		},

		//获取表格容器距页面头部的距离
		handleScrollx() {
			this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top
		},
		// 获取处罚类型列表
		// async getAuxiliaryTypes() {
		//   let res = await getAuxiliaryTypeList();
		//   if (res.code == 200) {
		//     this.auxiliaryTypes = res.rows;
		//   }
		// },
		// 更改处罚选择
		// changeType() {
		//   let cur = this.auxiliaryTypes.find((item) => {
		//     return item.id == this.form.auxiliaryConsumablesTypeId;
		//   });
		//   if (cur) {
		//     this.form.auxiliaryConsumablesTypeName = cur.name;
		//   }
		// },
		/** 查询处罚列表 */
		getList() {
			this.loading = true
			this.queryParams.type = 2 // 处罚
			if (this.queryParams.awardtime) {
				this.queryParams.awardTimeStart = this.queryParams.awardtime[0]
				this.queryParams.awardTimeEnd = this.queryParams.awardtime[1]
			} else {
				this.queryParams.awardTimeStart = undefined
				this.queryParams.awardTimeEnd = undefined
			}
			let params = deepClone(this.queryParams)
			params.awardtime = undefined
			listQuality(params).then(response => {
				this.auxiliaryConsumablesList = response.rows
				this.total = response.total
				this.loading = false
			})
		},
		// 取消按钮
		cancel() {
			this.open = false
			this.reset()
		},
		// 表单重置
		reset() {
			this.form = {
				id: undefined,
				recordNumber: undefined,
				number: undefined,
				informantName: undefined,
				deptId: undefined,
				deptName: undefined,
				awardPerson: undefined,
				belongingDeptId: undefined,
				belongingDept: undefined,
				rewardMethodKey: undefined,
				awardtime: undefined,
				awardTimeEnd: undefined,
				awardTimeStart: undefined,
				fileNumber: undefined,
				remark: undefined,
				awardType: undefined,
				awardDept: undefined,
				type: 2
			}
			this.resetForm("form")
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1
			this.saveSearchState()    
			this.getList()
		},
		resetQuerys() {
			this.resetForm("queryForm")
			this.queryParams = {
				pageNum: 1,
				pageSize: this.queryParams.pageSize,
				awardPerson: undefined,
				awardtime: undefined,
				awardTimeEnd: undefined,
				awardTimeStart: undefined,
				approvalStatus: undefined
			}
			// this.queryParams.awardtime = undefined;
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm("queryForm")
			this.queryParams = {
				pageNum: 1,
				pageSize: this.queryParams.pageSize,
				awardPerson: undefined,
				awardtime: undefined,
				awardTimeEnd: undefined,
				awardTimeStart: undefined,
				approvalStatus: undefined
			},
			this.clearSearchCache() 
				// this.queryParams.awardtime = undefined;
				this.handleQuery()
		},
		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map(item => item.id)
			this.single = selection.length !== 1
			this.multiple = !selection.length
		},
		// 更多操作触发
		handleCommand(command, row) {
			this[command](row)
		},
		// 部门名赋值
		changeDept() {
			this.form.deptName = this.$refs.deptref.getCheckedNodes()[0].label
		},
		changeBelongingDept() {
			this.form.belongingDept = this.$refs.belongingDeptref.getCheckedNodes()[0].label
		},
		/** 新增按钮操作 */
		handleAdd() {
			this.reset()
			this.open = true
			this.title = "申请"
			// this.getAuxiliaryTypes();
			// 获取记录编号
			this.getCode()
			// 部门列表
			this.getdeptlist()
		},
		// 部门列表
		getdeptlist() {
			deptTreeSelect().then(ret => {
				this.deptList = ret.data
			})
		},
		// 获取编号
		getCode() {
			getNumber().then(ret => {
				this.form.recordNumber = ret.msg
			})
		},

		/** 修改按钮操作 */
		handleUpdate(row) {
			this.reset()
			const id = row.id || this.ids
			getQuality(id).then(response => {
				this.form = response.data
				this.open = true
				this.title = "修改处罚"
				let data = response.data.awardTimeStart ? [response.data.awardTimeStart, response.data.awardTimeEnd] : undefined
				this.$set(this.form, "awardtime", data)
			})
			// 部门列表
			this.getdeptlist()
		},
		/** 提交按钮 */
		submitForm() {
			this.$refs["form"].validate(valid => {
				if (valid) {
					this.form.awardTimeStart = this.form.awardtime ? this.form.awardtime[0] : undefined
					this.form.awardTimeEnd = this.form.awardtime ? this.form.awardtime[1] : undefined
					if (this.form.id != undefined) {
						updateQuality(this.form).then(response => {
							this.$modal.msgSuccess("修改成功")
							this.open = false
							this.getList()
						})
					} else {
						addQuality(this.form).then(response => {
							this.$modal.msgSuccess("新增成功")
							this.open = false
							this.getList()
						})
					}
				}
			})
		},
		/** 删除按钮操作 */
		handleDelete(row) {
			const ids = row.id || this.ids
			this.$modal
				.confirm("是否确认删除处罚的数据项？")
				.then(function () {
					return delQuality(ids)
				})
				.then(() => {
					this.getList()
					this.$modal.msgSuccess("删除成功")
				})
				.catch(() => { })
		},
		// 获取审批详情
		showApproveList(row) {
			if (row.approvalStatus == "0") {
				return false
			}
			this.openRecords = true
			approvalRecord({
				id: row.id,
				workflowType: "8"
			}).then(res => {
				this.openRecords = true
				this.approveRecord = res.data
			})
		},
		// 质量考核附件
		handleAnnex(row) {
			this.$router.push({
				path: "/attachment/attachmentUpload",
				query: {
					TableId: row.id,
					typeId: 31,
					perm: "quality:qualityExam2:annex",
					// queryParams: JSON.stringify(this.queryParams),
					paths: "/quality/qualityExam2",
				}
			})
		},
		// 提交
		handleSubmits(row) {
			const _this = this
			this.$modal
				.confirm(`是否确认提交数据项？`)
				.then(function () {
					return submitQuality({
						workIds: _this.ids,
						workflowType: "8"
					})
				})
				.then(() => {
					_this.getList()
					_this.$modal.msgSuccess("提交成功")
					_this.$refs.table.clearSelection()
				})
				.catch(() => { })
		},
		// 提交
		handleSubmit(row) {
			this.$modal
				.confirm("是否确认提交数据项？")
				.then(function () {
					let data = {
						workId: row.id,
						workflowType: "8",
						// 1是提交，3是重复提交
						submitStatus: row.approvalStatus == "0" ? "1" : "2"
					}
					return submitQuality(data)
				})
				.then(() => {
					this.getList()
					this.$modal.msgSuccess("操作成功")
				})
				.catch(err => {
					console.log(err)
				})
		},

		// 审批
		handleApprove(row) {
			if (row.id) {
				this.approveRow = {
					id: row.id,
					repairId: row.repairId
				}
			} else {
				this.approveRow = {}
			}
			this.openApprove = true
		},
		// 审批取消
		async cancelApprove(ret) {
			if (!ret.flag) {
				this.openApprove = false
				return false
			}
			let data = {
				approvalStatus: ret.approvalStatus,
				causeRejection: ret.causeRejection,
				workflowType: "8"
			}
			this.approveRow.id ? (data.id = this.approveRow.id) : (data.ids = this.ids)
			const loading = this.$loading({
				lock: true,
				text: "Loading",
				spinner: "el-icon-loading",
				background: "rgba(0, 0, 0, 0.7)"
			})
			let res = await qualityApprove(data)
			loading.close()
			if (res.code == 200) {
				this.$modal.msgSuccess("操作成功")
				this.getList()
			}
			this.openApprove = false
		}
	}
}
</script>
<style lang="scss" scoped>
::v-deep .el-table__fixed-header-wrapper .fixed-width {
	width: 180px !important;
}
</style>
